package mycinema.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import mycinema.dao.BaseDao;
import mycinema.dao.CategoryDao;
import mycinema.entity.Category;

public class CategoryDaoImpl extends BaseDao implements CategoryDao{

/*	public List<Category> getAll() {
		List<Category> list = new ArrayList<Category>();
		ResultSet rs = null;
		this.openConnection();
		String sql = "select * from category";
		try {
			rs = this.executeQuery(sql, null);
			while(rs.next()){
				int id = rs.getInt("id");
				String name = rs.getString("name");
				Category c = new Category(id, name);
				list.add(c);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			this.closeResource();
		}
		return list;
	}*/
	public static void main(String[] args) {
		CategoryDaoImpl dao =  new CategoryDaoImpl();
		List<Category> list = dao.getAll();
		for(Category c: list){
			System.out.println(c.getId()+"\t"+c.getName());
		}
	}

	public List<Category> getAll() {
		List<Category> list = new ArrayList<Category>();
		ResultSet rs = null ;
		String sql = "select * from category";
		
		this.openConnection();
		try {
			rs = executeQuery(sql, null);
			while(rs.next()){
				int id = rs.getInt("id");
				String name = rs.getString("name");
				Category c = new Category(id, name);
				list.add(c);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeResource();
		}
		
		return list;
	}
}
